/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CrearGrupo.java
 *
 * Created on 31-ago-2011, 10:59:44
 */

package Ventanas;

import Objetos.PropiedadesIP;
import Proxies.CtrlCrearGrupoWS;
import Proxies.CtrlCrearGrupoWSService;
import Proxies.CtrlRelojSistemaWSService;
import Proxies.CtrlUsuariosWS;
import Proxies.CtrlUsuariosWSService;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import javax.xml.namespace.QName;

/**
 *
 * @author Sebas
 */
public class CrearGrupo extends javax.swing.JFrame {

    /** Creates new form CrearGrupo */
    private DefaultTableModel modeloListarUsr;
    private DefaultTableModel modeloModeradores;
    private DefaultTableModel modeloCreadores;
    CtrlUsuariosWS ctrlUsu;
    
    public CrearGrupo() {
        initComponents();
        PropiedadesIP props = PropiedadesIP.getInstance();
        String IP = props.getServidorCentralIP();
        URL dirUsr = null;
        try {
            dirUsr = new URL(IP + "CtrlUsuarios?wsdl");
        } catch (MalformedURLException ex) {
            Logger.getLogger(Amistades.class.getName()).log(Level.SEVERE, null, ex);
        }
        QName qNaUsr = new QName("http://WebServices/", "CtrlUsuariosWSService");
        ctrlUsu = new CtrlUsuariosWSService(dirUsr, qNaUsr).getCtrlUsuariosWSPort();
        crearTablaUsuarios();
        crearTablaCreadores();
        buttonGroup1.add(jRadioButton_Moderador);
        buttonGroup1.add(jRadioButton_Participante);
        jRadioButton_Participante.setSelected(true);
        
    }
    
    private void crearTablaUsuarios(){
        
        modeloListarUsr = new DefaultTableModel();
        modeloModeradores = new DefaultTableModel();

        JTable_buscarUsr.setModel(modeloListarUsr);
        JTable_moderadores.setModel(modeloModeradores);
        
        Object [] fila = new Object[3];
        
        Iterator<Proxies.DataUsuario> itera = ctrlUsu.listaUsuarios().getItem().iterator();
        Proxies.DataUsuario usr;
        modeloListarUsr.addColumn("Nick");
        modeloListarUsr.addColumn("Email");
        modeloListarUsr.addColumn("Nombre");
        modeloModeradores.addColumn("Nick");
        modeloModeradores.addColumn("Mail");
        modeloModeradores.addColumn("Nombre");
        modeloModeradores.addColumn("Tipo");
        TableColumn colTipo = JTable_moderadores.getColumnModel().getColumn(3);
        JComboBox comboTipo = new JComboBox();
        comboTipo.addItem("Moderador");
        comboTipo.addItem("Participante");
        colTipo.setCellEditor(new DefaultCellEditor(comboTipo));
        
        
        JTable_buscarUsr.setRowSelectionAllowed(true);
        JTable_buscarUsr.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        
        while (itera.hasNext()){
            usr = itera.next();
            fila[0] = usr.getNick();
            fila[1] = usr.getCorreo();
            fila[2] = usr.getNombre();
            modeloListarUsr.addRow(fila);
            JTable_buscarUsr.setRowSelectionInterval(0, 0);
        }
    }
    
    private void crearTablaCreadores(){
        
        modeloCreadores = new DefaultTableModel();

        JTable_buscarCreador.setModel(modeloCreadores);
        
        Object [] fila = new Object[3];
        
        Iterator<Proxies.DataUsuario> itera = ctrlUsu.listaUsuarios().getItem().iterator();
        Proxies.DataUsuario usr;
        modeloCreadores.addColumn("Nick");
        modeloCreadores.addColumn("Email");
        modeloCreadores.addColumn("Nombre");
        
        JTable_buscarCreador.setRowSelectionAllowed(true);
        JTable_buscarCreador.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        
        while (itera.hasNext()){
            usr = itera.next();
            fila[0] = usr.getNick();
            fila[1] = usr.getCorreo();
            fila[2] = usr.getNombre();
            modeloCreadores.addRow(fila);
        }
        JTable_buscarCreador.setRowSelectionInterval(0, 0);
        
    }
    
    private void actualizarTablaCreadores() {
        //if (JTable_buscarCreador.getSelectedRowCount() == 0) {

            TableModel modelo = JTable_buscarCreador.getModel();
            final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(modelo);
            JTable_buscarCreador.setRowSorter(sorter);
            String text = JTextField_BuscarCreador.getText();
            JTable_buscarCreador.setRowSelectionInterval(0, 0);
            if (text.length() == 0) {
                sorter.setRowFilter(null);
            } else {
                sorter.setRowFilter(RowFilter.regexFilter(text));
            }
            
        //}
    }
    
    private void actualizarTablaModeradores() {
        
        
        TableModel modelo = JTable_moderadores.getModel();
        final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(modelo);
        JTable_moderadores.setRowSorter(sorter);
        String text = "";
        JTable_moderadores.setRowSelectionInterval(0, 0);
        if (text.length() == 0) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter(text));
        }



    }
    
    private void actualizarTablaUsuarios(){
        TableModel modelo = JTable_buscarUsr.getModel();
        final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(modelo);
        JTable_buscarUsr.setRowSorter(sorter);
        JTable_buscarUsr.setRowSelectionInterval(0, 0);
        String text = JTextField_BuscarUsuario.getText();
        if (text.length() == 0) {
            sorter.setRowFilter(null);
        } else {
            sorter.setRowFilter(RowFilter.regexFilter(text));
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jButton_CrearGrupo = new javax.swing.JButton();
        jTextField_nomGrupo = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea_descGrupo = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton_agregarModeradores = new javax.swing.JButton();
        jButton_quitarModeradores = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton_VerGruposSistema = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jTextField_imgGrupo = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        JTable_buscarUsr = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        JTable_moderadores = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        JTextField_BuscarUsuario = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jRadioButton_Moderador = new javax.swing.JRadioButton();
        jRadioButton_Participante = new javax.swing.JRadioButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        JTable_buscarCreador = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        JTextField_BuscarCreador = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();

        setTitle("RED - Crear Grupo");

        jLabel1.setText("RED - CREAR GRUPO");

        jButton_CrearGrupo.setText("Crear Grupo");
        jButton_CrearGrupo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_CrearGrupoMouseClicked(evt);
            }
        });

        jTextField_nomGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_nomGrupoActionPerformed(evt);
            }
        });

        jTextArea_descGrupo.setColumns(20);
        jTextArea_descGrupo.setRows(5);
        jScrollPane1.setViewportView(jTextArea_descGrupo);

        jLabel2.setText("Nombre del grupo");

        jLabel3.setText("Descripcion del grupo");

        jLabel4.setText("Agregar miembros");

        jButton_agregarModeradores.setText(">>");
        jButton_agregarModeradores.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_agregarModeradoresMouseClicked(evt);
            }
        });

        jButton_quitarModeradores.setText("<<");
        jButton_quitarModeradores.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_quitarModeradoresMouseClicked(evt);
            }
        });

        jLabel5.setText("Usuarios del Sistema");

        jLabel6.setText("Miembros");

        jButton_VerGruposSistema.setText("Ver grupos del sistema");
        jButton_VerGruposSistema.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_VerGruposSistemaMouseClicked(evt);
            }
        });

        jLabel7.setText("Imagen del grupo");

        jTextField_imgGrupo.setText("http://");

        JTable_buscarUsr.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nick", "Email", "Nombre"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(JTable_buscarUsr);

        JTable_moderadores.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nick", "Email", "Nombre", "Tipo"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(JTable_moderadores);

        jButton1.setText("Cancelar");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        JTextField_BuscarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JTextField_BuscarUsuarioActionPerformed(evt);
            }
        });
        JTextField_BuscarUsuario.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                JTextField_BuscarUsuarioPropertyChange(evt);
            }
        });
        JTextField_BuscarUsuario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTextField_BuscarUsuarioKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                JTextField_BuscarUsuarioKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                JTextField_BuscarUsuarioKeyTyped(evt);
            }
        });

        jLabel8.setText("Buscar");

        jRadioButton_Moderador.setText("Moderador");

        jRadioButton_Participante.setText("Participante");

        JTable_buscarCreador.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nick", "Email", "Nombre"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(JTable_buscarCreador);

        jLabel9.setText("Usuarios del Sistema");

        JTextField_BuscarCreador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JTextField_BuscarCreadorActionPerformed(evt);
            }
        });
        JTextField_BuscarCreador.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                JTextField_BuscarCreadorPropertyChange(evt);
            }
        });
        JTextField_BuscarCreador.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JTextField_BuscarCreadorKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                JTextField_BuscarCreadorKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                JTextField_BuscarCreadorKeyTyped(evt);
            }
        });

        jLabel10.setText("Buscar");

        jLabel11.setText("Creador del grupo");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(39, 39, 39)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel3)
                    .add(jLabel2)
                    .add(jLabel7))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jScrollPane1)
                    .add(jTextField_nomGrupo)
                    .add(jTextField_imgGrupo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 211, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(662, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .add(300, 300, 300)
                .add(jButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton_VerGruposSistema)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton_CrearGrupo)
                .addContainerGap(413, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel5)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 85, Short.MAX_VALUE)
                                .add(jLabel8)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(JTextField_BuscarUsuario, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 133, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel6)
                                .addContainerGap(528, Short.MAX_VALUE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jButton_quitarModeradores)
                                    .add(jButton_agregarModeradores))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 419, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())))
                    .add(layout.createSequentialGroup()
                        .add(192, 192, 192)
                        .add(jRadioButton_Participante)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jRadioButton_Moderador)
                        .addContainerGap(668, Short.MAX_VALUE))))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(jLabel11)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel9)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 39, Short.MAX_VALUE)
                                .add(jLabel10)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(JTextField_BuscarCreador, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 133, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 139, Short.MAX_VALUE))
                            .add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE)))
                    .add(jLabel1))
                .add(484, 484, 484))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .add(30, 30, 30)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField_nomGrupo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(jTextField_imgGrupo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(27, 27, 27)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(jLabel9)
                        .add(6, 6, 6))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(JTextField_BuscarCreador, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel10))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel11)
                    .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(jLabel5)
                        .add(6, 6, 6))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel6)
                            .add(JTextField_BuscarUsuario, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel8))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel4)
                                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(jRadioButton_Participante)
                                    .add(jRadioButton_Moderador)))
                            .add(layout.createSequentialGroup()
                                .add(24, 24, 24)
                                .add(jButton_agregarModeradores)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jButton_quitarModeradores)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jButton1)
                            .add(jButton_VerGruposSistema)
                            .add(jButton_CrearGrupo))))
                .add(24, 24, 24))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField_nomGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_nomGrupoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_nomGrupoActionPerformed

    private void jButton_CrearGrupoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_CrearGrupoMouseClicked
        // TODO add your handling code here:
        boolean tieneNom = !(jTextField_nomGrupo.getText().isEmpty());
        if (JTable_buscarCreador.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(null, "Debe seleccionar un creador de grupo", "ERROR", JOptionPane.WARNING_MESSAGE);
        }
        if (!tieneNom){
            JOptionPane.showMessageDialog(null, "Debe seleccionar un nombre para el grupo", "ERROR", JOptionPane.WARNING_MESSAGE);
            jTextField_nomGrupo.requestFocusInWindow();
        }
        else{

            PropiedadesIP props = PropiedadesIP.getInstance();
            String IP = props.getServidorCentralIP();
            URL dirGr = null;
            try {
                dirGr = new URL(IP + "CtrlCrearGrupo?wsdl");
            } catch (MalformedURLException ex) {
                Logger.getLogger(CrearGrupo.class.getName()).log(Level.SEVERE, null, ex);
            }
            QName qNaGr = new QName("http://WebServices/", "CtrlCrearGrupoWSService");

            CtrlCrearGrupoWS ctrlGrupo = new CtrlCrearGrupoWSService(dirGr, qNaGr).getCtrlCrearGrupoWSPort();
            
            Proxies.DataGrupo dg = new Proxies.DataGrupo();
            dg.setNombre(jTextField_nomGrupo.getText());
            dg.setDesc(jTextArea_descGrupo.getText());
            dg.setImg(jTextField_imgGrupo.getText());
            GregorianCalendar c = new GregorianCalendar();
           
            URL dirReloj = null;
            try {
                dirReloj = new URL(IP + "CtrlRelojSistema?wsdl");
            } catch (MalformedURLException ex) {
                Logger.getLogger(CrearGrupo.class.getName()).log(Level.SEVERE, null, ex);
            }
            QName qNaReloj = new QName("http://WebServices/", "CtrlRelojSistemaWSService");
            dg.setFechaCreacion(new CtrlRelojSistemaWSService(dirReloj, qNaReloj).getCtrlRelojSistemaWSPort().getTime());
            int h = JTable_moderadores.getRowCount();

            ArrayList<String> listModeradores = new ArrayList<String>();
            ArrayList<String> listParticipantes = new ArrayList<String>();

            for (int i = 0; i < h; i++) {
                if ("Moderador".equals(JTable_moderadores.getValueAt(i, 3).toString())) {
                    listModeradores.add(modeloModeradores.getValueAt(i, 1).toString());
                } else {
                    listParticipantes.add(modeloModeradores.getValueAt(i, 1).toString());
                }
            }

            dg.getModeradores().addAll(listModeradores);
            dg.getParticipantes().addAll(listParticipantes);

            if (JTable_buscarCreador.getSelectedRow() == -1) {
                dg.setCreador(JTable_buscarCreador.getModel().getValueAt(0, 1).toString());
            } else {
                dg.setCreador(JTable_buscarCreador.getModel().getValueAt(JTable_buscarCreador.getSelectedRow(), 1).toString());
            }

            dg.setCantParticipantes(listModeradores.size() + listParticipantes.size() + 1);

            String detalleGrupo =
                    "Detalle de Grupo:\n"
                    + "\nNombre: " + dg.getNombre()
                    + "\nDescripción: " + dg.getDesc()
                    + "\nCantidad de Participantes: " + dg.getCantParticipantes()
                    + "\nImagen: " + dg.getImg()
                    + "\nFecha de creacion: " + dg.getFechaCreacion().toGregorianCalendar().get(Calendar.DAY_OF_MONTH)
                    + "/" + (dg.getFechaCreacion().toGregorianCalendar().get(Calendar.MONTH) + 1)
                    + "/" + dg.getFechaCreacion().toGregorianCalendar().get(Calendar.YEAR)
                    + " " + dg.getFechaCreacion().toGregorianCalendar().get(Calendar.HOUR_OF_DAY)
                    + ":" + dg.getFechaCreacion().toGregorianCalendar().get(Calendar.MINUTE)
                    + ":" + dg.getFechaCreacion().toGregorianCalendar().get(Calendar.SECOND)
                    + "\nUsuarios:";

            detalleGrupo += "\n - Mail: " + dg.getCreador() + " (Creador)";

            Iterator<String> itera = dg.getModeradores().iterator();
            String du;

            while (itera.hasNext()) {
                du = itera.next();
                detalleGrupo += "\n - Mail: " + du + " (Moderador)";

            }

            itera = dg.getParticipantes().iterator();

            while (itera.hasNext()) {

                du = itera.next();
                detalleGrupo += "\n - Mail: " + du + " (Participante)";

           }


            int i = JOptionPane.showConfirmDialog(null,detalleGrupo);

            if (i == 0) {
                ctrlGrupo.crearGrupo(dg);
                JOptionPane.showMessageDialog(null, "Grupo creado");
            }

            if (i == 1) {
                this.setVisible(false);
            }

        }
        
        
    }//GEN-LAST:event_jButton_CrearGrupoMouseClicked

    private void jButton_agregarModeradoresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_agregarModeradoresMouseClicked
        // TODO add your handling code here:
        String errMens = "";
        boolean error = false;
        if (JTable_buscarUsr.getSelectedRowCount() == 0) {
            errMens += " Seleccione al menos un usuario para agregar";
            error = true;
        }

        if (!error) {
            String nom, nick, mail, tipo = "";
            nick = (JTable_buscarUsr.getValueAt(JTable_buscarUsr.getSelectedRow(), 0)).toString();
            mail = (JTable_buscarUsr.getValueAt(JTable_buscarUsr.getSelectedRow(), 1)).toString();
            nom = (JTable_buscarUsr.getValueAt(JTable_buscarUsr.getSelectedRow(), 2)).toString();
            int fila = JTable_buscarUsr.getSelectedRow();

            if (jRadioButton_Moderador.isSelected()) {
                tipo = "Moderador";
            }
            if (jRadioButton_Participante.isSelected()) {
                tipo = "Participante";
            }

            Object[] p = new Object[4];
            p[0] = nick;
            p[1] = mail;
            p[2] = nom;
            p[3] = tipo;

            modeloListarUsr.removeRow(fila);
            modeloModeradores.addRow(p);
            modeloCreadores.removeRow(fila);
            actualizarTablaCreadores();
            actualizarTablaUsuarios();
            actualizarTablaModeradores();
        } else {
            JOptionPane.showMessageDialog(null, errMens, "ERROR!", JOptionPane.WARNING_MESSAGE);
        }

    }//GEN-LAST:event_jButton_agregarModeradoresMouseClicked

    private void jButton_quitarModeradoresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_quitarModeradoresMouseClicked
        // TODO add your handling code here:
        
        String nom, nick, mail;
        nick = (JTable_moderadores.getValueAt(JTable_moderadores.getSelectedRow(), 0)).toString();
        mail = (JTable_moderadores.getValueAt(JTable_moderadores.getSelectedRow(), 1)).toString();
        nom = (JTable_moderadores.getValueAt(JTable_moderadores.getSelectedRow(), 2)).toString();
        int fila = JTable_moderadores.getSelectedRow();

        Object [] p = new Object[3];
        p[0]=nick;
        p[1]=mail;
        p[2]=nom;
        
        modeloModeradores.removeRow(fila);
        modeloListarUsr.addRow(p);
        modeloCreadores.addRow(p);
        actualizarTablaCreadores();
        actualizarTablaUsuarios();
        actualizarTablaModeradores();
    }//GEN-LAST:event_jButton_quitarModeradoresMouseClicked

    private void jButton_VerGruposSistemaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_VerGruposSistemaMouseClicked
        // TODO add your handling code here:
        
        PropiedadesIP props = PropiedadesIP.getInstance();
        String IP = props.getServidorCentralIP();
        URL dirGr = null;
        try {
            dirGr = new URL(IP + "CtrlCrearGrupo?wsdl");
        } catch (MalformedURLException ex) {
            Logger.getLogger(CrearGrupo.class.getName()).log(Level.SEVERE, null, ex);
        }
        QName qNaGr = new QName("http://WebServices/", "CtrlCrearGrupoWSService");
        CtrlCrearGrupoWS ctrlGrupo = new CtrlCrearGrupoWSService(dirGr, qNaGr).getCtrlCrearGrupoWSPort();
        Iterator itera = ctrlGrupo.listarGrupos().getItem().iterator();
        String grupos = "";
        while (itera.hasNext()){
            grupos += itera.next()+"\n";
        }
        JOptionPane.showMessageDialog(null, grupos, "Grupos en el sistema sistema", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_jButton_VerGruposSistemaMouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jButton1MouseClicked

    private void JTextField_BuscarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JTextField_BuscarUsuarioActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_JTextField_BuscarUsuarioActionPerformed

    private void JTextField_BuscarUsuarioPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_JTextField_BuscarUsuarioPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_JTextField_BuscarUsuarioPropertyChange

    private void JTextField_BuscarUsuarioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTextField_BuscarUsuarioKeyPressed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_JTextField_BuscarUsuarioKeyPressed

    private void JTextField_BuscarUsuarioKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTextField_BuscarUsuarioKeyReleased
        // TODO add your handling code here:
        
        actualizarTablaUsuarios();
        
    }//GEN-LAST:event_JTextField_BuscarUsuarioKeyReleased

    private void JTextField_BuscarUsuarioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTextField_BuscarUsuarioKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_JTextField_BuscarUsuarioKeyTyped

    private void JTextField_BuscarCreadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JTextField_BuscarCreadorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_JTextField_BuscarCreadorActionPerformed

    private void JTextField_BuscarCreadorPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_JTextField_BuscarCreadorPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_JTextField_BuscarCreadorPropertyChange

    private void JTextField_BuscarCreadorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTextField_BuscarCreadorKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_JTextField_BuscarCreadorKeyPressed

    private void JTextField_BuscarCreadorKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTextField_BuscarCreadorKeyReleased
        // TODO add your handling code here:
        actualizarTablaCreadores();
    }//GEN-LAST:event_JTextField_BuscarCreadorKeyReleased

    private void JTextField_BuscarCreadorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_JTextField_BuscarCreadorKeyTyped
        // TODO add your handling code here:
       
    }//GEN-LAST:event_JTextField_BuscarCreadorKeyTyped

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CrearGrupo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable JTable_buscarCreador;
    private javax.swing.JTable JTable_buscarUsr;
    private javax.swing.JTable JTable_moderadores;
    private javax.swing.JTextField JTextField_BuscarCreador;
    private javax.swing.JTextField JTextField_BuscarUsuario;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton_CrearGrupo;
    private javax.swing.JButton jButton_VerGruposSistema;
    private javax.swing.JButton jButton_agregarModeradores;
    private javax.swing.JButton jButton_quitarModeradores;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JRadioButton jRadioButton_Moderador;
    private javax.swing.JRadioButton jRadioButton_Participante;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextArea jTextArea_descGrupo;
    private javax.swing.JTextField jTextField_imgGrupo;
    private javax.swing.JTextField jTextField_nomGrupo;
    // End of variables declaration//GEN-END:variables

    
    
}
